package com.example.myapplication.adapter.recyclerViewAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.myapplication.R;
import com.example.myapplication.entity.CommentSong;

import java.util.List;

public class CommentSongAdapter extends RecyclerView.Adapter<CommentSongAdapter.CommentSongHolder> {
    private List<CommentSong.HotCommentsBean> hotCommentsBeanList ;
    private Context context;

    public void setData(List<CommentSong.HotCommentsBean> hotCommentsBeanList){
        this.hotCommentsBeanList = hotCommentsBeanList;
        notifyDataSetChanged();
    }
    public CommentSongAdapter(Context context){
         this.context = context;
    }

    @NonNull
    @Override
    public  CommentSongHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment_song,parent,false);
        return new  CommentSongHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull  CommentSongHolder holder, int position) {
        CommentSong.HotCommentsBean hotCommentsBean = hotCommentsBeanList.get(position);
        holder.name_comment_song.setText(hotCommentsBean.getUser().getNickname());
        holder.content_comment_song.setText(hotCommentsBean.getContent());
        RoundedCorners roundedCorners= new RoundedCorners(30);
        RequestOptions options= RequestOptions
                .bitmapTransform(roundedCorners)
                .circleCrop();
        Glide.with(context).load(hotCommentsBean.getUser().getAvatarUrl())
                .centerCrop().apply(options).into(holder.img_comment_song);
    }

    @Override
    public int getItemCount() {
        return hotCommentsBeanList==null?0:hotCommentsBeanList.size();
    }

    class  CommentSongHolder extends RecyclerView.ViewHolder{
        ImageView img_comment_song;
        TextView name_comment_song;
        TextView content_comment_song;
        public  CommentSongHolder(@NonNull View itemView) {
            super(itemView);
            img_comment_song=itemView.findViewById(R.id.img_comment_song);
            name_comment_song=itemView.findViewById(R.id.name_comment_song);
            content_comment_song=itemView.findViewById(R.id.content_comment_song);
        }
    }
}